package com.red.wine.adapter;

import com.red.wine.R;

import android.view.View;
import android.view.ViewGroup;

 
public abstract class LoadingAdapter extends RootAdapter {

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public int getViewTypeCount() {
        return super.getViewTypeCount();
    }

    public int getCount() {
        return 0;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    public static interface Delegate {
        boolean needLoading();
    }

    public static interface OnLoadingRowShowingHandler {
        void onLoadingRowShowing(LoadingAdapter adapter);
    }

    private OnLoadingRowShowingHandler handler;
    protected Delegate delegate;

    public OnLoadingRowShowingHandler getHandler() {
        return handler;
    }

    public void setHandler(OnLoadingRowShowingHandler handler) {
        this.handler = handler;
    }

    public Delegate getDelegate() {
        return delegate;
    }

    public void setDelegate(Delegate value) {
        delegate = value;
    }

    protected abstract boolean isLoadingRow(int position);

    public View getView(int position, View convertView, ViewGroup parent) {
        super.getView(position, convertView, parent);
        if (delegate != null && delegate.needLoading()
                && isLoadingRow(position)) {
            if (handler != null) {
                handler.onLoadingRowShowing(this);
            }
            View result = View.inflate(parent.getContext(),R.layout.loading_row, null);
            result.setFocusable(false);
            result.setFocusableInTouchMode(false);
            result.setClickable(false);
            return result;
        }
        return null;
    }
}
